#lang racket

(define (average a b) (/ (+ a b) 2))

(define (make-point x y) (cons x y))

(define (x-point point) (car point))

(define (y-point point) (cdr point))

(define (print-point p)
  (newline)
  (display "(")
  (display (x-point p))
  (display ", ")
  (display (y-point p))
  (display ")"))

(define (make-segment p1 p2) (cons p1 p2))

(define (start-segment seg) (car seg))

(define (end-segment seg) (cdr seg))

(define p1 (make-point 10 20))

(define p2 (make-point 30 40))

(define (midpoint-segment seg)
  (let ((x1 (car (car seg)))
        (y1 (cdr (car seg)))
        (x2 (car (cdr seg)))
        (y2 (cdr (cdr seg))))
    (make-point (average x1 x2) (average y1 y2))))

(define s (make-segment p1 p2))

(print-point s)
(newline)
(midpoint-segment s)

